import { useUserStore } from '@/stores/user'

// 权限控制指令
export const permission = {
  mounted(el, binding) {
    const { value } = binding
    if (!value) return
    
    const userStore = useUserStore()
    const hasPermission = userStore.hasPermission(value)
    
    if (!hasPermission) {
      // 如果没有权限，移除元素
      el.parentNode?.removeChild(el)
    }
  }
}

// 角色控制指令
export const role = {
  mounted(el, binding) {
    const { value } = binding
    if (!value) return
    
    const userStore = useUserStore()
    const hasRole = userStore.hasRole(value)
    
    if (!hasRole) {
      // 如果没有角色权限，移除元素
      el.parentNode?.removeChild(el)
    }
  }
} 